{template "header.html"}
<!-- end header -->
<link href="{THEME_PATH}assets/global/plugins/bootstrap-touchspin/bootstrap.touchspin.css" rel="stylesheet" type="text/css" />
<script src="{THEME_PATH}assets/global/plugins/fuelux/js/spinner.min.js" type="text/javascript"></script>
<script src="{THEME_PATH}assets/global/plugins/bootstrap-touchspin/bootstrap.touchspin.js" type="text/javascript"></script>


<script type="text/javascript" src="{THEME_PATH}assets/js/sku.js"></script>
<script type="text/javascript">
    $(function () {
        $(".dr_buy_num").TouchSpin({
            step: 1,
            min: 1,
            max: 9999999
        });
        $(".dr_buy_num").change(function () {
            var num = $(this).val();
            var iid = $(this).attr('iid');
            $.ajax({
                type: "GET",
                url: '/index.php?s=store&c=cart&m=update&id='+iid+'&num='+num,
                dataType: "jsonp",
                success: function (json) {
                    dr_cmf_tips(json.code, json.msg);
                    if (json.code) {
                        $('#dr_cart_nums').html(json.data.nums);
                        $('#dr_total_'+iid).html(json.data.total);
                    }
                },
                error: function(HttpRequest, ajaxOptions, thrownError) {
                    alert(HttpRequest.responseText);
                }
            });
        });
    });
    function dr_delete_cart_all() {

        $('.checkboxes').each(function() {
            var checked = jQuery(this).is(":checked");
            if (checked) {
                dr_cart_del(jQuery(this).val());
            }
        });
    }
    // ajax提交
    function dr_ajax_order_submit() {


        var loading = layer.load(2, {
            shade: [0.3,'#fff'], //0.1透明度的白色背景
            time: 100000000
        });


        $.ajax({
            type: "POST",
            dataType: "json",
            url: "{dr_url('store/cart/order')}",
            data: $("#myform").serialize(),
            success: function(json) {
                layer.close(loading);
                if (json.code == 1) {
                    dr_cmf_tips(1, json.msg);
                    setTimeout("window.location.href = '"+json.data.url+"'", 2000);
                } else {
                    dr_cmf_tips(0, json.msg);
                    $('#dr_row_'+json.data.id).addClass('has-error');
                }
            },
            error: function(HttpRequest, ajaxOptions, thrownError) {
                layer.closeAll('loading');
                alert(HttpRequest.responseText);
            }
        });
    }
</script>

<section class="main-content-area">
    <div class="container">
        <!-- bradcame start -->
        <div class="row">
            <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
                <div class="greentect_bradcame">
                    <ul>
                        <li><a href="{SITE_URL}">首页</a></li>
                        <li>购物车</li>
                    </ul>
                </div>
            </div>
        </div>
        <!-- bradcame end -->


        <form class="form-horizontal" method="post" role="form" id="myform">
            {dr_form_hidden()}
            <div class="">

                <div class="portlet-body  ">
                    <table class="table table-bordered table-checkable  ">
                        <thead>
                        <tr>
                            <th width="50">
                                <label class="mt-table mt-checkbox mt-checkbox-single mt-checkbox-outline">
                                    <input checked="checked" type="checkbox" class="group-checkable" data-set=".checkboxes" />
                                    <span></span>
                                </label>
                            </th>
                            <th width="90" class="cart_product" style="text-align: center">商品</th>
                            <th>详情</th>
                            <th width="180" class="">单价</th>
                            <th width="180">数量</th>
                            <th width="180" class="">总价</th>
                            <th width="60" class="action"></th>
                        </tr>
                        </thead>
                        <tbody>

                        {loop $list $i $t}
                        {php $sku_name=dr_string2array($t.sku_name);}
                        <tr id="dr_row_{$t.id}">
                            <td style="">
                                <label class="mt-table mt-checkbox mt-checkbox-single mt-checkbox-outline">
                                    <input type="checkbox" checked="checked" class="checkboxes" name="ids[]" value="{$t.id}" />
                                    <span></span>
                                </label>
                            </td>
                            <td class="cart_product" style="text-align: center">
                                <a href="{$t.url}" title="{$t.title}"><img style="width: 70px; height: 70px;" src="{dr_thumb($t.thumb, 70, 70)}"></a>
                            </td>
                            <td class="cart_description">
                                <p class="product-name"> <a href="{$t.url}" title="{$t.title}">{dr_strcut($t.title, 50)}</a></p>
                                {loop $sku_name $i $c}
                                <small class="cart_ref">{$i}: {$c} </small>
                                {/loop}
                            </td>
                            <td class="price pprice">
                                {if $t.yuan}
                                <p>￥<span class="regular-price">{number_format($t.price, 2)}</span>元</p>
                                <p class="pyuan">￥<span>{number_format($t.yuan, 2)}</span>元</p>
                                <p>{$t.p_info}</p>
                                {else}
                                ￥<span class="regular-price">{number_format($t.price, 2)}</span>元
                                {/if}
                            </td>
                            <td class="qty" style="width: 150px">
                                <input class="dr_buy_num" iid="{$t.id}" type="text" value="{$t.quantity}">
                            </td>
                            <td class="price">
                                ￥<span id="dr_total_{$t.id}" class="regular-price">{number_format($t.price * $t.quantity, 2)}</span>元
                            </td>
                            <td class="action">
                                <a href="javascript:dr_cart_del('{$t.id}');">删除</a>
                            </td>
                        </tr>
                        {/loop}
                        </tbody>
                    </table>
                </div>
                <table class="table  table-checkable  ">
                    <tfoot>
                    <tr>
                        <td class="action" style="width: 50px;border-top:0">
                            <label class="mt-table mt-checkbox mt-checkbox-single mt-checkbox-outline">
                                <input checked="checked" type="checkbox" class="group-checkable" data-set=".checkboxes" />
                                <span></span>
                            </label>
                        </td>
                        <td colspan="7" style="border-top:0" class="text-left">
                            <label><button type="button" onclick="dr_delete_cart_all()" class="btn red btn-sm"> <i class="fa fa-trash"></i> {dr_lang('删除')}</button></label>
                            <label><button type="button" onclick="dr_ajax_submit('{FC_NOW_URL}', 'myform', 1000, '{FC_NOW_URL}')" class="btn green btn-sm"> <i class="fa fa-refresh"></i> {dr_lang('刷新')}</button></label>
                            <label><button type="button" onclick="dr_ajax_order_submit()" class="btn green btn-sm"> <i class="fa fa-rmb"></i> {dr_lang('立即下单结算')}</button></label>
                        </td>
                    </tr>
                    </tfoot>
                </table>
            </div>

        </form>

    </div>
</section>


{template "footer.html"}